package com.cxx.home.controller;

import com.cxx.common.ReadView;
import com.cxx.common.WriteView;
import com.cxx.home.dto.plan.PlanDto;
import com.cxx.home.dto.plan.PlanStatsDto;
import com.cxx.home.vo.PlanQueryVo;
import com.cxx.home.service.PlanService;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/plan")
@Tag(name = "日程安排")
public class PlanController {
    @Resource
    private PlanService planService;

    @Operation(summary = "查询日程安排")
    @GetMapping("")
    public @JsonView(ReadView.class) List<PlanDto> queryPlan(PlanQueryVo query) {
        return planService.queryPlan(query);
    }

    @Operation(summary = "新增日程安排")
    @PostMapping("")
    public Boolean addPlan(@RequestBody @JsonView(WriteView.class) @Validated PlanDto planDto) {
        return planService.addPlan(planDto);
    }

    @Operation(summary = "更新日程安排")
    @PutMapping("/{id}")
    public Boolean updatePlan(@PathVariable("id") long id,
                              @RequestBody @JsonView(WriteView.class) PlanDto planDto) {
        return planService.updatePlan(id, planDto);
    }

    @Operation(summary = "删除日程安排")
    @DeleteMapping("/{id}")
    public Boolean deletePlan(@PathVariable("id") long id) {
        return planService.deletePlan(id);
    }

    @Operation(summary = "更新日程状态")
    @PutMapping("/{id}/status")
    public Boolean setPlanStatus(@PathVariable("id") long id, @RequestParam("status") boolean status) {
        return planService.setPlanStatus(id, status);
    }

    @Operation(summary = "查看日程统计")
    @GetMapping("/stats")
    public PlanStatsDto queryPlanStats() {
        return planService.queryPlanStats();
    }
}
    